package com.unitech.drinks.controller;

import com.unitech.drinks.model.SystemInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class HealthCheckController {

    @Autowired
    private ApplicationContext appContext;

    @GetMapping("/healthcheck")
    public SystemInfo healthCheck() {

        // 获得配置信息${spring.profiles.active}
        String env = appContext.getEnvironment().getProperty("spring.profiles.active", String.class);
        String version = appContext.getEnvironment().getProperty("drinks.version", String.class);

        return SystemInfo.builder()
                .status("available")
                .env(env)
                .version(version)
                .build();
    }
}
